<?php $this -> load -> view('adminx/header'); ?>
<!-- BEGIN CONTAINER -->
<div class="page-container">
    <!-- BEGIN SIDEBAR -->
    <?php $this -> load -> view('adminx/mune'); ?>
    <!-- END SIDEBAR -->
    <!-- BEGIN CONTENT -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
            <!-- /.modal -->
            <h3 class="page-title"> <?php echo $title; ?> <small><?php echo $en; ?></small></h3>
            <div class="page-bar">
                <ul class="page-breadcrumb">
                    <li>
                        <i class="fa fa-home"></i>
                        <a href="/adminx">首页</a>
                        <i class="fa fa-angle-right"></i>
                    </li>
                    <li>
                        <a href="/iadmin/team"><?php echo $title; ?></a>
                        <i class="fa fa-angle-right"></i>
                    </li>
                    <li>
                        <a href="#"><?php echo $action;?><?php echo $title; ?></a>
                    </li>
                </ul>
            </div>
            <!-- END PAGE HEADER-->
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-lg-12 col-md-12">
                    <div class="portlet light ">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="icon-share font-red-sunglo"></i>
                                <span class="caption-subject font-red-sunglo bold uppercase"><?php echo $title; ?>管理</span>
                            </div>
                            <div class="actions">
                                <a class="btn btn-circle btn-icon-only blue" href="javascript:;" onclick="alert_ts('<?php echo $this -> config -> item('xt_ts'); ?>')"> <i class=" icon-bulb"></i> </a>
                                <a class="btn btn-circle btn-icon-only btn-default fullscreen" href="javascript:;"> </a>
                            </div>
                        </div>
                        <div class="portlet-body">
                            <form role="form" method="post" id="add_team">
                                <div class="form-group">
                                    <label>名称</label>
                                    <input type="text" class="form-control required" name="name" placeholder="名称" value="<?php echo (isset($data) ? $data['name'] : '')?>"/>
                                </div>
                                <div class="form-group">
                                    <label>头像</label>
                                    <?php echo $this -> form -> doform('pic', 'head_image', '', (isset($data) ? $data['head_image'] : '')); ?>
                                </div>
                                <div class="form-group">
                                    <label>队长</label>
                                    <div class="flex-box">
                                        <input type="text" class="form-control" id="leander_key" name="leader-key" placeholder="队长" value="<?php echo (isset($data) ? $data['nickname'] : '')?>"/>
                                        <button type="button" class="btn blue" id="leander_search_btn">
                                            <i class="fa fa-send"></i>
                                            搜索
                                        </button>
                                    </div>
                                    <select class="form-control required" id="leander_select" name="leader">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                                <button type="reset" class="btn default">
                                    <i class="fa fa-refresh"></i>
                                    重置
                                </button>
                                <button type="submit" class="btn blue">
                                    <i class="fa fa-send"></i>
                                    <?php echo $action;?>
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- BEGIN QUICK SIDEBAR -->
    <?php $this -> load -> view('adminx/lt'); ?>
    <!-- END QUICK SIDEBAR -->
</div>
<style>
    .flex-box {
        display: -webkit-box;
        margin-bottom: 10px;
    }
    .flex-box input{
        display: -webkit-box;
        -webkit-box-flex: 1;
    }
</style>

<?php $this -> load -> view('adminx/footer'); ?>
<link href="/mex/global/plugins/uk/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="/mex/global/plugins/uk/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/mex/global/plugins/uk/umeditor.min.js"></script>
<script type="text/javascript" src="/mex/global/plugins/uk/lang/zh-cn/zh-cn.js"></script>

<script src="/mex/global/plugins/ajaxfileupload.js"></script>
<script>
    $(function() {
        var um = UM.getEditor('myEditor');
        up_form($("#add_team"), <?php if($action == '添加'){?>"/iadmin/team/add<?php }else{ ?>"/iadmin/team/up/<?php echo (isset($data) ? $data['team_id'] : '');} ?>", "<?php echo $action;?>战队", function(msg) {
            if (msg.type == 1) {
                alert_ts('<?php echo $action;?>战队成功，3秒后回到战队列表...');
                setTimeout(function(){
                    window.location.href="/iadmin/team";
                },3000);
            } else {
                alert_ts('提交失败');
            }
        });
    });

    $(function() {
        $('#leander_search_btn').on('click', function (e) {
            console.log('change');
            $.ajax({
                type: 'get',
                url : "/iadmin/team/get_leander_user",
                dataType: 'json',
                data: {
                    key: $('#leander_key').val().trim()
                }
            })
                .done(function (result) {
                    var len = result.length;
                    var leanderSelect = $('#leander_select');
                    leanderSelect.html('');
                    for (var i = 0; i < len; i++) {
                        var item = result[i];
                        leanderSelect.append('<option value="'+item['mid']+'">'+item['nickname']+'</option>')
                    }
                })
                .fail(function () {
                    alert('网络错误');
                })
        })
    });
</script>